// pages/profileTab/feedback/feedback.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    srcImg:[],
    count1:0,
    noteMaxLen: 100, // 最多放多少字
    info: "",
    noteNowLen: 0, //备注当前字数
    srcList: [
      "../../../images/feedback/jieTu.jpg", 
      "../../../images/feedback/jieTu.jpg", 
      "../../../images/feedback/jieTu.jpg"],
    curImgSrc: ''
  },

  // 选择图片
  chooseImg:function(e) {
    var that=this;
    console.log(e);
    var index = e.currentTarget.dataset.index;
    var srcPath = "srcList[" + index + "]";
    console.log(srcPath);
    wx.chooseImage({
      count: 1,
      sizeType: ['compressed'],
      sourceType: ['album'],
      success(res) {
        console.log(res)
        var tempFilePaths = res.tempFilePaths
        that.data.srcImg[that.data.count1] = tempFilePaths[0]
        that.data.count1++
        that.setData({
          [srcPath]: tempFilePaths[0],
          curImgSrc: tempFilePaths[0]
        }),
        console.log(that.data)
      }
    })
  },
  // 监听字数
  bindTextAreaChange: function (e) {
    // console.log(e.detail)
    var that = this;
    var value = e.detail.value;
    var len = parseInt(value.length);
    if (len > that.data.noteMaxLen)
      return;
    that.setData({
      info: value,
      noteNowLen: len
    })
  },
  //点击提交按钮
  submit:function(){
    var that = this; 
    wx.showToast({
      title: '提交成功',
      icon: 'success',
      duration: 1500,
      mask: false,
      success: function () {
        //提交之后表单清空
        that.setData({
          noteNowLen: 0,
          info: ''
        })
      }
    })
  },
  //提交表单
  formSubmit: function(e) {
    console.log("提交的用户反馈的表单信息如下：")
    console.log(e)
    var that = this;
    var formData = e.detail.value.content;
    for(var i=0;i<3;i++){
      wx.uploadFile({
        url: 'https://www.enjoyyz.com:8443/yinzuo/feedBack',
        filePath: that.data.srcImg[i],
        name: 'pic',
        header: {
          "Content-Type": "multipart/form-data"
        },
        formData: {
          openid: app.globalData.openid,
          content: JSON.stringify(formData)
        },
        success(res) {
          console.log(res.data);
          console.log(that.data.curImgSrc, 'that.data.curImgSrc')
        },
        fail(res) {
          console.log("上传失败，错误信息如下：")
          console.log(res.data)
        }
      })
    }
   
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})